package top.suven.base.http.admin.sec.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.suven.base.core.mybatis.PageData;
import top.suven.base.http.admin.sec.dao.RoleMenuDao;
import top.suven.base.http.admin.sec.model.RoleMenu;
import top.suven.base.http.admin.sec.service.RoleMenuService;
import top.suven.base.http.admin.sec.vo.response.RoleMenuResponseVo;
import top.suven.base.http.enums.EnableStatusEnum;
import top.suven.base.util.utilize.BeanUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Title: RoleMenuService.java
 * @Description: 角色菜单权限的业务处理服务类
 * @author lixiangling
 * @date   2018/08/13 16:59:19
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
@Component("roleMenuService")
public class RoleMenuServiceImpl implements RoleMenuService {
    private final static Logger logger = LoggerFactory.getLogger(RoleMenuServiceImpl.class);
    @Autowired
    private RoleMenuDao roleMenuDao;
    /**
     * @Title: 获取角色菜单权限分页信息
     * @Description:
     * @param roleMenu @{Link RoleMenu}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public PageData<RoleMenuResponseVo> getRoleMenuPage(RoleMenu roleMenu, int start, int pageSize){
        int count = roleMenuDao.countEntity(roleMenu);
        if(count == 0){
            return new PageData<RoleMenuResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<RoleMenu> roleMenuList = roleMenuDao.findPageEntity(roleMenu, start, pageSize);
        if(roleMenuList == null || roleMenuList.isEmpty()){
            return new PageData<RoleMenuResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<RoleMenuResponseVo> roleMenuResponseList = roleMenuList.stream().map(roleMenuResponse -> {
            RoleMenuResponseVo roleMenuResponseVo = new RoleMenuResponseVo();
            BeanUtil.copyProperties(roleMenuResponse, roleMenuResponseVo);
            return roleMenuResponseVo;
        }).collect(Collectors.toList());
        return new PageData<RoleMenuResponseVo>(roleMenuResponseList,count);
    }
    /**
     * @Title: 获取角色菜单权限列表信息
     * @Description:
     * @param roleMenu @{Link RoleMenu}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public List<RoleMenu> getRoleMenuList(RoleMenu roleMenu){
        return roleMenuDao.findEntity(roleMenu);
    }
    /**
     * @Title: 获取角色菜单权限列表信息
     * @Description:
     * @param roleCodeList @{Link List}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Override
    public List<RoleMenu> getRoleMenuByRoleCodeList(List<String> roleCodeList) {
        return roleMenuDao.getRoleMenuByRoleCodeList(roleCodeList);
    }

    /**
     * @Title: 新增角色菜单权限信息
     * @Description:
     * @param roleMenu @{Link RoleMenu}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void addRoleMenu(RoleMenu roleMenu){
        roleMenuDao.createEntity(roleMenu);
    }
    /**
    * @Title: 修改角色菜单权限信息
    * @Description:
    * @param roleMenu @{Link RoleMenu}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 16:59:19
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void updRoleMenu(RoleMenu roleMenu){
        roleMenuDao.updateEntity(roleMenu);
    }
   /**
    * @Title: 获取角色菜单权限信息
    * @Description:
    * @param id @{Link Long}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 16:59:19
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public RoleMenu getRoleMenu(Long id){
        RoleMenu roleMenu = new RoleMenu();
        roleMenu.setRoleMenuId(id);
        return roleMenuDao.retrieveEntity(roleMenu);
    }
    /**
     * @Title: 删除角色菜单权限信息
     * @Description:
     * @param ids @{Link Long[]}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void del(Long[] ids){
        roleMenuDao.del(Arrays.asList(ids));
    }
   /**
    * @Title: 启用角色菜单权限信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 16:59:19
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOn(Long[] ids){
        roleMenuDao.updateEnableStatus(EnableStatusEnum.ENABLE.getIndexStr(), Arrays.asList(ids));
    }
   /**
    * @Title: 禁用角色菜单权限信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 16:59:19
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOff(Long[] ids){
        roleMenuDao.updateEnableStatus(EnableStatusEnum.DISABLE.getIndexStr(), Arrays.asList(ids));
    }
}